import { createSlice } from '@reduxjs/toolkit';

const userMousePositions = createSlice({
  name: 'mousePositions',
  initialState: [{ type: '', visible: false, value: 0, x: 0, y: 0 }],
  reducers: {
    setMousePositions: (state, action) => {
      const index = state.findIndex((item) => item.value === action.payload.value);
      if (index !== -1) {
        state.splice(index, 1);
      } else {
        state.push(action.payload);
      }
      // state.visible = action.payload.visible;
      // state.value = action.payload.value;
      // state.x = action.payload.x;
      // state.y = action.payload.y;
    },
  },
});

export const { setMousePositions } = userMousePositions.actions;
export default userMousePositions.reducer;
